package com.gjzt.business.callBackLog.service;

import java.util.List;


import com.gjzt.business.callBackLog.inter.CallBackLogMapper;
import com.gjzt.business.callBackLog.model.CallBackLog;
import com.eastdigit.servlet.ReqBean;
import com.eastdigit.system.model.BusinessException;
import com.eastdigit.system.model.SqlBuilder;
import com.eastdigit.system.service.BaseService;
import com.eastdigit.util.DateUtil;
import com.eastdigit.util.StringUtil;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CallBackLogService extends BaseService {

    @Autowired
    private CallBackLogMapper callBackLogMapper;

    /**
     * 查询
     *
     * @param reqBean
     * @return
     */
    public JSONObject findCallBackLog(ReqBean reqBean) {
        SqlBuilder sqlBuilder = new SqlBuilder("", new Object[0]);
        return this.queryTable(sqlBuilder, reqBean.getPageSize(), reqBean.getPageIndex());
    }

    /**
     * 新增
     *
     * @param reqBean
     */
/*    public void addCallBackLog(ReqBean reqBean) {
        CallBackLog callBackLog = getCallBackLog(reqBean);
        callBackLog.setId(intId());// 手动设置Id
        callBackLog.setMakeTime(callBackLog.getModifyTime());

        callBackLogMapper.insert(callBackLog);
    }
*/
    /**
     * 修改
     *
     * @param reqBean
     */
    public void updateCallBackLog(ReqBean reqBean) {
        String id = reqBean.getInfo("id");
        if (StringUtil.isEmpty(id)) {
            throw new BusinessException("获取主键失败");
        }
        CallBackLog callBackLog = getCallBackLog(reqBean);
        callBackLogMapper.updateByPrimaryKeySelective(callBackLog);
    }

    /**
     * 删除
     *
     * @param reqBean
     */
    public void removeCallBackLog(ReqBean reqBean) {
        String id = reqBean.getInfo("id");
        if (StringUtil.isEmpty(id)) {
            throw new BusinessException("获取主键失败");
        }
        callBackLogMapper.deleteByPrimaryKey(id);
    }

    /**
     * 从表单获取对象
     *
     * @param reqBean
     * @return
     */
    private CallBackLog getCallBackLog(ReqBean reqBean) {
        CallBackLog callBackLog = new CallBackLog();

        callBackLog.setId(reqBean.getInfo("id"));
        callBackLog.setOrderId(reqBean.getInfo("orderId"));
        callBackLog.setMakeTime(DateUtil.parseDateTime(reqBean.getInfo("makeTime")));

        return callBackLog;
    }

}